package jjn.hot;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/2 15:44
 */
public class LeetCode3 {
    public int lengthOfLongestSubstring(String s) {
        Map<Character, Integer> map = new HashMap<>();
        int maxLength = 0;
        int left = 0;
        for (int i = 0; i < s.length(); i++) {
            if (map.containsKey(s.charAt(i))) {
                int current = map.get(s.charAt(i)) + 1;
                System.out.println("current = " + current + ", i = " + i);
                left = Math.max(current, left);
            }
            maxLength = Math.max(maxLength, i - left + 1);
            map.put(s.charAt(i), i);
        }
        return maxLength;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String s = scanner.nextLine();
            int lengthOfLongestSubstring = new LeetCode3().lengthOfLongestSubstring(s);
            System.out.println(lengthOfLongestSubstring);
        }
    }
}
